/*
* 提示类 createBy yongwang 2015/7/8
* */
(function(w){
    tip = {
        toast: function(str){
            if($("#toast").length == 0){
                var toast = document.createElement("div");
                toast.id = "toast";
                toast.className = "toast";
                document.body.appendChild(toast);

                //toast提示还原
                $("#toast")[0].addEventListener('webkitAnimationEnd', function(){
                    this.className = "toast";
                }, false);
            }

            $("#toast").text(str);
            $("#toast").addClass("toasts");
        },
        confirm: function(data){
            console.log(data);
            this.data = data;

            if($("#tip_confirm").length == 0){
                var confirm = document.createElement("div");
                confirm.id = "tip_confirm";
                confirm.className = "tip-confirm";
                confirm.innerHTML = "<div><div id='tipContent'>"+data.str+"</div></div><div class = 'confirm-button'><span id = 'confirm_no'>取消</span><span id = 'confirm_yes'>确定</span></div>";
                document.body.appendChild(confirm);
                //$("#mask").css("display","block");

            }else{
                try{
                    $("#tipContent").text(data.str);
                }catch(exception)
                {
                    console.log((exception.stack))
                }
                $("#tip_confirm").css("display","block");
                $("#mask").css("display","block");
            }
            if($("#tip_confirm").length > 0) {
                $("#tip_confirm").delegate("#confirm_no,#confirm_yes", "click", function () {
                    $("#tip_confirm").css("display", "none");
                    if (this.id == "confirm_no") {
                        if (data.cancelMethod) {
                            data.cancelMethod();
                        }
                        return false;
                    } else if (this.id == "confirm_yes") {
                        if (data.method) {
                            if(data.data)
                            {
                                console.log(data.data);
                                data.method(data);
                            }
                            else {
                                data.method();
                            }
                        }
                    }
                });
            }
        }
    };


    w.tip = tip;
}(window));